package com.sp3.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;

/**
 * Created by IntelliJ IDEA.
 * User: zhimingli
 * Date: 14-3-18
 * Time: 上午10:41
 * redirect forword
 */
@Controller
public class TestController {
    @RequestMapping("/tt/index")
    public ModelAndView index(HttpServletRequest request, @RequestParam(value = "endId", required = false) String endId
            , @RequestParam(value = "workspaceId", required = false) String workspaceId
            , @RequestParam(value = "redirect", required = false) String redirect) {

        System.out.println(endId + "-----" + workspaceId + "----" + redirect);


        String forward = (String) request.getAttribute("forward");
        System.out.println("forward=" + forward);
        return new ModelAndView("/test");
    }


    @RequestMapping("/tt/redirect")
    public ModelAndView report(HttpServletRequest request) {
        HashMap map = new HashMap();
        map.put("redirect", "rrrr");
        return new ModelAndView("redirect:/tt/index", map);
    }

    @RequestMapping("/tt/forward")
    public ModelAndView tt(HttpServletRequest request) {
        HashMap map = new HashMap();
        map.put("endId", "aaa");
        map.put("workspaceId", "aaaa");
        request.setAttribute("forward", "fffffff");
        return new ModelAndView("forward:/tt/index", map);
    }

    @RequestMapping("/tt/model")
    public String model(Model model) {
        model.addAttribute("username", "username");
        return "redirect:/tt/index";
    }


}
